<!--  Nguyen Huu Nhat -->
<?php 
@session_start();
include '../Security/CheckAdmin.php';
include '../DataBase/ConnectDB.php';
 include '../Home/DefineVar.php';
 
 mysql_select_db(MYSQL_DATABASE,$link);
 $userId = mysql_real_escape_string($_GET['userId']);
	$query = "SELECT * FROM ".MYSQL_TABLE_USERINFOR." WHERE userId=$userId;";
	//print("<br>".$query);
        $result = mysql_query($query, $link);
        if($result){
        	$resultuser = mysql_fetch_row($result);
        }
?>
<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script type="text/javascript">
//入力したデータの検索
function onlyLetter(t, e){
	c = e.keyCode;
if(!((c>=65 && c<=90) || (c>=97&&c<=122) || c==8))
	t.value = t.value.substring(0, t.value.length-1);
}

function checkMail() {
  var mail = document.forms[0].elements[5].value;
  var reg = new RegExp("\\w+([-+.\']\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*");
  x = document.getElementById('mailCheck');
  if(!reg.test(mail) || mail == "")
  { 
  //alert("Your email address isn't valid!");
  x.innerHTML='無効メールアドレス';
   return false;
  }
  else {
	  //x.innerHTML='valid mail';
	  x.innerHTML ='';   
	  return true;
  }
}

function checkPassWord(){
	var invalid = " "; // Invalid character is a space
	var minLength = 6; // Minimum length
	var pass1 = document.forms[0].elements[1].value;
	var pass2 = document.forms[0].elements[2].value;

	x=document.getElementById('passwordCheck');
	//alert("Your email address isn't valid!");
	//Check bang nhau
	if(pass1 != pass2){
		//alert("Your email address isn't valid!");
		x.innerHTML='パスワードとパスワード確認が違う';
		return false;
	}
//	else
	//	x.innerHTML='bang nhau';

	// Check length
	if(pass1.length < minLength){
		x.innerHTML ='パスワードの長さは６より小さい';
		return false;
	}

	//Check khoang trang
	if(pass1.indexOf(invalid) >-1){
		x.innerHTML ='パスワードでが空欄を含む';
		return false;
	}

	//Check chu so
	re = /[0-9]/;
	if(!re.test(pass1)) {
		x.innerHTML ='パスワードでは数字がない';
		 return false; 
		 } 

	 //Check chu thuong
	 re = /[a-z]/;
	if(!re.test(pass1)) {
		x.innerHTML ='パスワードでは小文字がない';
		 return false; 
		 } 

	 //Check chu hoa
	 re = /[A-Z]/;
	if(!re.test(pass1)) {
		x.innerHTML ='パスワードでは大文字がない';
		 return false; 
		 } 
	x.innerHTML ='';
	return true;
}
function checkName(){
	var name = document.forms[0].elements[3].value;
	
	x=document.getElementById('nameCheck');
	if((name.length ==0) || (name == " ")){
		x.innerHTML='名前はない';
		return false;
	}
	x.innerHTML ='';
	return true;
}

function checkPhone(){
	var phone = document.forms[0].elements[4].value;
	
	x=document.getElementById('phoneCheck');
	if((phone.length ==0) || (phone == " ")){
		x.innerHTML='電話番号はない';
		return false;
	}
	x.innerHTML ='';
	return true;
} 

function checkAddress(){
	var address = document.forms[0].elements[6].value;

	x= document.getElementById('addressCheck');
	if((address.length == 0) || (address ==" ")){
		x.innerHTML = '住所がない';
		return false;
	}
	x.innerHTML ='';
	return true;
}

function validatorOnSubmit(){
	var result = true;

	if(!checkMail()) result = false;
	//if(!checkPassWord()) result = false;
	if(!checkName()) result = false;
	if(!checkPhone()) result = false;
	if(!checkAddress()) result = false;
	
	return result;
}
</script>
</head>
<body>
<!--ユーザの更新情報を入力する画面-->
<h1>ユーザ情報</h1>
<form action = 'UpdateUserEx.php' method='post' onSubmit="return validatorOnSubmit()">
<table>
<tr><td>アカウント名</td>
<td><input type='text' name='accountName' <?php echo "value='".$resultuser[0]."'";?> ></td>
<td id='accountCheck'></td></tr>

<tr><td>パスワード</td>
<td><input type='password' name='pass1' value="0" ></td>
<td id='passwordCheck'></td></tr>

<tr><td>パスワード確認</td>
<td><input type='password' name='pass2' value="0" ></td>
<td id='passwordCheck'></td></tr>

<tr><td>名前</td>
<td><input type='text' name='fullName' <?php echo "value='".$resultuser[1]."'";?> ></td>
<td id='nameCheck'></td></tr>

<tr><td>電話番号</td>
<td><input type='text' name='phone' <?php echo 'value='.$resultuser[4];?> ></td>
<td id='phoneCheck'></td></tr>

<tr><td>メールアドレス</td>
<td><input type='text' name='mail' <?php echo 'value='.$resultuser[3];?>></td>
<td id='mailCheck'></td></tr>

<tr><td>住所</td>
<td><input type='text' name='address' size=50 <?php echo "value='".$resultuser[5]."'"; ?>></td>
<td id='addressCheck'></td></tr>
</table>
<input type=checkbox value=true  name='isAdmin'/>管理者<br></br>
<input type='hidden' name='userId' <?php echo "value ='".$userId."'"; ?> />
<input type='submit' name='delete' value='削除' />
<input type='submit' name='submit' value='更新' />
</form>	
</body></html>